package com.chenqi.myblog.controller;

import com.chenqi.myblog.model.Comment;
import com.chenqi.myblog.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * @description: 评论控制器
 * @program: myblog
 * @author: ChenQi
 * @create: 2021-02-2021/2/5-20-13
 */
@Controller
@RequestMapping("/blog")
public class CommentController {

    @Autowired
    private CommentService commentService;


    /**
     * 新增留言
     * @param comment
     * @param modelAndView
     * @return
     */
    @PostMapping("/addComment")
    public ModelAndView comment(Comment comment,ModelAndView modelAndView) {
        commentService.saveComment(comment);
        modelAndView.setViewName("redirect:/blog/detail?id="+comment.getBlogId());
        return modelAndView;
    }
}
